:-dynamic norm/3.
:-dynamic antecedent/3.

antecedent(action(none, _,_, _), -1, nil).

satisfied(action(N, S, R, T)) :- antecedent(action(N, S, R, T), _, fulfilled).

status(A, L, _, Time, fulfilled) :- satisfied(A). 
status(A, L, _, Time, pending) :- \+satisfied(A), Time < L.
status(A, L, D, Time, violated) :- \+satisfied(A), Time > D.
status(A, L, D, Time, liveline_violated) :- \+satisfied(A), L =< Time, Time < D.

canPerform(C, Agent, Action) :- permitted(C, Agent, Action).

obligation(C, consequent(action(A, S, R, Ticker), L, D, Type)) :- norm(C, _, consequent(action(A, S, R, Ticker), L, D, Type)).

eval_v(A+B,CV,Vars):-eval_v(A,AV,Vars),eval_v(B,BV,Vars),CV is AV+BV.
eval_v(A-B,CV,Vars):-eval_v(A,AV,Vars),eval_v(B,BV,Vars),CV is AV-BV.
eval_v(A*B,CV,Vars):-eval_v(A,AV,Vars),eval_v(B,BV,Vars),CV is AV*BV.
eval_v(Num,Num,Vars):-number(Num).
eval_v(Var,Value,Vars):-atom(Var),member(Var/Value,Vars).

eval(A+B,CV):-eval(A,AV),eval(B,BV),CV is AV+BV.
eval(A-B,CV):-eval(A,AV),eval(B,BV),CV is AV-BV.
eval(A*B,CV):-eval(A,AV),eval(B,BV),CV is AV*BV.
eval(Num,Num):-number(Num).

